package cn.bocweb.spinning.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebView;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.bocweb.spinning.R;
import cn.bocweb.spinning.model.Bean.HelpAddressBean;
import cn.bocweb.spinning.presenter.Imp.UserPresenterImp;
import cn.bocweb.spinning.presenter.UserPresenter;
import cn.bocweb.spinning.util.Constant;
import cn.bocweb.spinning.view.common.BaseActivity;
import de.greenrobot.event.EventBus;

public class HelpDetailActivity extends BaseActivity {
    UserPresenter presenter;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.help_detail_web)
    WebView helpDetailWeb;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help_detail);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);

        initToolbar();
        initModel();
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    public void onEventMainThread(HelpAddressBean bean) {
        if (bean.getReturn_code() == 0) {
            initWebView(bean.getUrl());
        }
    }

    private void initWebView(String url) {
        helpDetailWeb.loadUrl(url);
    }

    private void initModel() {
        Intent intent = getIntent();
        String id = intent.getStringExtra(Constant.HELP_DETAIL);
        UserPresenter userPresenter = new UserPresenterImp();
        userPresenter.helpAddress(id);
    }

    private void initToolbar() {
        toolbar.setTitle("帮助详情");
        toolbar.setTitleTextColor(getResources().getColor(R.color.white));
        toolbar.setNavigationIcon(R.mipmap.btn_exit);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
